2.3 - Remaking first mod in UnityExplorer


Brief explanation

In the previous lesson we have made our first mod just by using these two lines of code.


LocalPlayer.FpCharacter.SetWalkSpeed(10);
LocalPlayer.FpCharacter.SetRunSpeed(20);
            

You are now probably wondering where these two lines comes from and how did I know i have to write those words. This is where UnityExplorer (but also dnSpy) will greatly help in seeing what we can do and how to do it. This time, instead of coding the mod, we will set the player walk and run speed in game using UnityExplorer. If you haven't installed it before, refer to Installing must have programs.

Using UnityExplorer to remake the mod

Now that you have UnityExplorer installed, it's time to launch the game and load into a savegame (preferably a new one to not mess with your normal stuff)
When you gain player control, press F7 to bring up UnityExplorer on screen. You will see a top bar menu and another window. At the top of the window switch to the Object Search tab,
then in the Class filter we need to type LocalPlayer as we did in our coded mod to get a reference of it. After that, click on one of the results and you will be presented with all the stuff which has to do with it.
If you remember, in our code we wrote LocalPlayer.FpCharacter. This was needed as the SetWalkSpeed and SetRunSpeed methods are tied to the FirstPersonCharacter (FpCharacter in code).
So we basically need to chain things together using dots to reach what we want. Returning to our newly opened UnityExplorer window with LocalPlayer stuff, we can scroll down to search the FpCharacter, click Inspect and we will now see all FpCharacter tied stuff in a new window. If we scroll down to the S we can se our SetWalkSpeed and SetRunSpeed methods we used in our code before.
To change the corresponding value, click on Evaluate and enter the values accordingly.
To execute each method, click on the Evaluate button, then close UnityExplorer with F7. You can now see the player moves faster, and you can test it with different values to see that it works.
Note that these are run-time changes, and won't be saved after restarting the game, unlike a coded mod (but be careful that adding items or spawning something in the world then saving will persist).

What we learned

As you have seen, UnityExplorer is a really powerfull tool that can greetly help in mods making, allowing us to test things while in game and changing how the game behave.